<?php
namespace Cubemarketing\Model;

use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Sql\Sql;

class SaleHeadTable extends AbstractTableGateway
{
    protected $table ='saleHead';
    
    public function __construct(Adapter $adapter)
    {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new SaleHead());
        $this->initialize();
    }
    
    public function getSalestats($idStore)
    {
        $sql = new Sql($this->adapter); 
        $select = $sql->select(); 
        //$select->columns(array('orderDate', 'type'));
        $select->from(array('sh' => $this->table)); 
        $select->join(array('sr' => 'saleRow'), 
                'sh.idsaleHead = sr.idsaleHead', 
                array('quantity'));
        $select->where(array('sh.idStore' => $idStore));
        
        $statement = $sql->prepareStatementForSqlObject($select);
        $results = $statement->execute(); 
        
        $resultSet = $this->resultSetPrototype->initialize($results);

        return $resultSet; 
    }
}
